package com.jie.boot.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.jie.boot.domain.Task;
import com.jie.boot.domain.User;
import com.jie.boot.repository.UserRepository;


@Service
public class UserService {

	@Resource(name = "userRepository")
	private UserRepository userRepository;

	public User findOne(Long id) {
		return userRepository.getOne(id);
	}
	
	public List<User> findAll() {
        return userRepository.findAll();
    }
	
	@Transactional
	public User save(User user) {
		return userRepository.save(user);
	}
	
	public List<User> findByName(String name) {
        return userRepository.findByParams(name);
    }
	
	public List<User> findWithTask(String name, String taskName) {
	    User user = new User();
	    user.setName(name);
	    Task task = new Task();
	    task.setTitle(taskName);
        return userRepository.findWithTask(user, task);
    }
}
